//***************************************************************************
//*
//*	File:			dswl_genericwindow.cpp
//*	Description:	Wrapper for IGenericWindow interface
//*
//***************************************************************************

//
//--------------------------------------------------------------- PRECOMPILED
//

#include "stdafx.h"

//
//--------------------------------------------------- DECLARATION DEPENDENCIES
//

//
//--------------------------------------------------------------- DECLARATION
//

#include "../Inc/dswl_genericwindow.h"

//
//--------------------------------------------------- DEFINITION DEPENDENCIES
//

//
//-------------------------------------------------------------- PREPROCESSOR
//

#ifdef	_DEBUG
#define new DEBUG_NEW
#undef	THIS_FILE
static	char THIS_FILE[] = __FILE__;
#endif

//
//---------------------------------------------------------------- DEFINITION
//

/*
static void g_TestCasts()
{
	// test _safe_ conversions
	IGenericWindow* pITest;
	CIGenericWindow test	 ( pITest );
	CIGenericWindow test2 = pITest ;

	test = test2;
	test = pITest;

	#ifdef _DSWL_SWITCH_USE_AUTOCAST

	// test _critical_ conversions
	pITest = test;
	CComPtr< IGenericWindow > tmplTest = test;

	#endif
}
*/

//
//---------------------------------------------------------------------------------------------------
//*************************************     CON/DESTRUCTION     *************************************
//---------------------------------------------------------------------------------------------------
//

//***************************************************************************************************
//**																					  Constructor
//***************************************************************************************************
//**	@DOC		CONSTRUCTION
//**	@MFUNC		Default constructor
//**	@PARM		[in] A pointer to the interface to attach to
//**	@END
//***************************************************************************************************
//inline
CIGenericWindow::CIGenericWindow( IGenericWindow* a_pIGenericWindow /*= NULL*/ )
{
	this->m_pIGenericWindow = a_pIGenericWindow;
}

//***************************************************************************************************
//**																					   Destructor
//***************************************************************************************************
//**	@DOC		CONSTRUCTION
//**	@MFUNC		Default destructor
//**	@END
//***************************************************************************************************
//inline
CIGenericWindow::~CIGenericWindow()
{
	this->m_pIGenericWindow = NULL;	// explicitly release the interface now
}

//
//---------------------------------------------------------------------------------------------------
//***************************************     PROPERTIES     ****************************************
//---------------------------------------------------------------------------------------------------
//

//***************************************************************************************************
//**																				   GetApplication 
//***************************************************************************************************
//**	@DOC		PROPERTIES
//**	@MFUNC		Determines the application this window belongs to
//**	@RDESC		A pointer to the application's interface
//**	@END
//***************************************************************************************************
//inline
CIApplication CIGenericWindow::GetApplication( void ) const 
{
	//
	//	CHECK VALIDITY
	//
	if ( FALSE == this->IsValid() )
	{
		return NULL;
	}

	//
	//	DELEGATE
	//
	IDispatch*	pIDispatch = NULL;

	DSWL_VERIFY( this->m_pIGenericWindow->get_Application( &pIDispatch ) );

	//
	//	QUERY INTERFACE
	//
	CComQIPtr< IApplication, &IID_IApplication > pIApplication ( pIDispatch );	

	//
	//	REPELASE DISPATCH INTERFACE
	//
	DSWL_RELEASE_EX( pIDispatch, CIGenericWindow::GetApplication );

	//
	//	RETURN QUERIED INTERFACE
	//
	return pIApplication.p;												
}

//
//---------------------------------------------------------------------------------------------------
//***************************************     INFORMATION     ***************************************
//---------------------------------------------------------------------------------------------------
//

//***************************************************************************************************
//**																						   IsNull
//***************************************************************************************************
//**	@DOC		INFORMATION
//**	@MFUNC		Determines whether the internal pointer is <t NULL>
//**	@RDESC		<t TRUE> if the internal pointer is <t NULL>, <t FALSE> otherwise.
//**	@END
//***************************************************************************************************
//inline
BOOL CIGenericWindow::IsNull( void ) const
{
	return ( NULL == this->m_pIGenericWindow.p );
}

//***************************************************************************************************
//**																						  IsValid
//***************************************************************************************************
//**	@DOC		INFORMATION
//**	@MFUNC		Determines whether the internal pointer differs from <t NULL>
//**	@RDESC		<t TRUE> if the internal pointer differs from <t NULL>, <t FALSE> otherwise.
//**	@END
//***************************************************************************************************
//inline
BOOL CIGenericWindow::IsValid( void ) const
{
	return ( NULL != this->m_pIGenericWindow.p );
}

//
//---------------------------------------------------------------------------------------------------
//**************************************     MODIFICATION     ***************************************
//---------------------------------------------------------------------------------------------------
//

//***************************************************************************************************
//**																							Close
//***************************************************************************************************
//**	@DOC		MODIFICATION
//**	@MFUNC		Closes the window
//**	@PARM		[in] A flag indicating whether to save the window's document prior to closing
//**	@RDESC		The status
//**	@END
//***************************************************************************************************
//inline
DsSaveStatus CIGenericWindow::Close( BOOL a_bSave ) 
{
	ASSERT( this->IsValid() );

	CComVariant		varSave		( a_bSave	);
	DsSaveStatus	enuResult	;

	DSWL_VERIFY( this->m_pIGenericWindow->Close( varSave, &enuResult ) );

	return enuResult;
}

//
//---------------------------------------------------------------------------------------------------
//****************************************     OPERATORS     ****************************************
//---------------------------------------------------------------------------------------------------
//

//***************************************************************************************************
//**																					  operator ==
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Comparison operator
//**	@PARM		[in] The generic window to compare to
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
bool CIGenericWindow::operator == ( const CIGenericWindow& a_Other ) const 
{
	return this->m_pIGenericWindow == a_Other.m_pIGenericWindow;
}

//***************************************************************************************************
//**																					  operator !=
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Comparison operator
//**	@PARM		[in] The generic window to compare to
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
bool CIGenericWindow::operator != ( const CIGenericWindow& a_Other ) const 
{
	return this->m_pIGenericWindow != a_Other.m_pIGenericWindow;
}

//***************************************************************************************************
//**																					  operator <=
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Comparison operator
//**	@PARM		[in] The generic window to compare to
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
bool CIGenericWindow::operator <= ( const CIGenericWindow& a_Other ) const 
{
	return this->m_pIGenericWindow.p <= a_Other.m_pIGenericWindow.p;
}

//***************************************************************************************************
//**																					  operator >=
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Comparison operator
//**	@PARM		[in] The generic window to compare to
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
bool CIGenericWindow::operator >= ( const CIGenericWindow& a_Other ) const 
{
	return this->m_pIGenericWindow.p >= a_Other.m_pIGenericWindow.p;
}

//***************************************************************************************************
//**																					   operator <
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Comparison operator
//**	@PARM		[in] The generic window to compare to
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
bool CIGenericWindow::operator < ( const CIGenericWindow& a_Other ) const 
{
	return this->m_pIGenericWindow.p < a_Other.m_pIGenericWindow.p;
}

//***************************************************************************************************
//**																					   operator >
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Comparison operator
//**	@PARM		[in] The generic window to compare to
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
bool CIGenericWindow::operator > ( const CIGenericWindow& a_Other ) const 
{
	return this->m_pIGenericWindow.p > a_Other.m_pIGenericWindow.p;
}

//***************************************************************************************************
//**																					   operator =
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Copy operator
//**	@PARM		[in] The generic window to attach to
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
CIGenericWindow& CIGenericWindow::operator = ( IGenericWindow* a_pIOther ) 
{
	this->m_pIGenericWindow = a_pIOther;

	return (*this);
}

//***************************************************************************************************
//**																					   operator *
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Dereference operator
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
IGenericWindow* CIGenericWindow::operator * ( void ) 
{
	return this->m_pIGenericWindow.p;
}

//***************************************************************************************************
//**																				 const operator *
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Dereference operator
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
const IGenericWindow* CIGenericWindow::operator * ( void ) const 
{
	return this->m_pIGenericWindow.p;
}

//***************************************************************************************************
//**																					  operator ->
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Member access operator
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
IGenericWindow* CIGenericWindow::operator -> ( void ) 
{
	return * (*this);
}

//***************************************************************************************************
//**																				const operator ->
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		Member access operator
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
const IGenericWindow* CIGenericWindow::operator -> ( void ) const 
{
	return * (*this);
}

//---------------------------------------------------------------------------------------------------
//***************************************************************************************************
//---------------------------------------------------------------------------------------------------

#ifdef _DSWL_SWITCH_USE_AUTOCAST
#ifdef _DSWL_SWITCH_USE_UNSAFE_AUTOCAST

//***************************************************************************************************
//**																				 const operator *
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		TypeCast operator
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
CIGenericWindow::operator IGenericWindow* ( void ) const 
{
	return this->m_pIGenericWindow.p;
}

#else

//***************************************************************************************************
//**																					   operator *
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		TypeCast operator
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
CIGenericWindow::operator IGenericWindow* ( void ) 
{
	return this->m_pIGenericWindow.p;
}

//***************************************************************************************************
//**																				 const operator *
//***************************************************************************************************
//**	@DOC		OPERATORS
//**	@MFUNC		TypeCast operator
//**	@RDESC		
//**	@END
//***************************************************************************************************
//inline
CIGenericWindow::operator const IGenericWindow* ( void ) const 
{
	return this->m_pIGenericWindow.p;
}

#endif
#endif


